// 数据库类型枚举
export enum DatabaseType {
  MySQL = 'mysql',
  PostgreSQL = 'postgresql',
  SQLite = 'sqlite',
  SQLServer = 'sqlserver',
  DaMeng = 'dameng'
}

// 数据库配置
export interface DatabaseConfig {
  id: string
  name: string
  type: DatabaseType
  host: string
  port: number
  username: string
  password: string
  database?: string
  charset?: string
  timezone?: string
  sslMode?: string
  filePath?: string // SQLite
  options?: string
  isDefault?: boolean
  createdAt?: string
  updatedAt?: string
}

// 连接状态
export interface ConnectionStatus {
  connected: boolean
  version?: string
  lastPing?: string
  error?: string
}

// 数据库信息
export interface DatabaseInfo {
  name: string
  charset?: string
  collation?: string
  comment?: string
  size?: number
  tableCount?: number
  createdAt?: string
}

// 表信息
export interface TableInfo {
  name: string
  schema?: string
  type: string
  engine?: string
  collation?: string
  rowCount?: number
  dataLength?: number
  indexLength?: number
  comment?: string
  createdAt?: string
  updatedAt?: string
}

// 数据库列信息
export interface ColumnInfo {
  name: string
  type: string
  fullType: string
  length: number
  lengthDisplay?: string
  semanticType?: string
  originalLength?: number
  bytesPerChar?: number
  precision: number
  scale: number
  isNullable: boolean
  notNull: boolean
  isPrimaryKey: boolean
  primaryKey: boolean
  isAutoIncrement: boolean
  autoIncrement: boolean
  position: number
  defaultValue: string
  comment: string
  charset: string
  collation: string
  extra: string
  values?: string[]
  rawInfo?: Record<string, any>
  
  // UI特定属性
  displayLength?: string
  displayComment?: string
}

// 索引信息
export interface IndexInfo {
  name: string
  type: string
  isUnique: boolean
  isPrimary: boolean
  columns: string[]
  comment?: string
}

// 查询结果
export interface QueryResult {
  columns: string[]
  rows: Record<string, any>[]
  rowCount: number
  executeTime?: number
  error?: string
  warning?: string
}

// 查询历史
export interface QueryHistory {
  id: string
  connectionId: string
  database: string
  query: string
  timestamp: Date
  duration: number
  rowCount: number
  error?: string
  isFavorite?: boolean
}

// 数据库能力
export interface DatabaseCapabilities {
  supportsTransactions: boolean
  supportsSchemas: boolean
  supportsViews: boolean
  supportsStoredProcedures: boolean
  supportsFunctions: boolean
  supportsTriggers: boolean
  supportsCTEs: boolean
  supportsWindowFunctions: boolean
  supportsJSONType: boolean
  supportsArrayType: boolean
  supportsFullTextSearch: boolean
  supportsPartitioning: boolean
  supportsForeignKeys: boolean
  supportsCheckConstraints: boolean
  supportsPartialIndexes: boolean
  supportsExpressionIndexes: boolean
}

// 表数据过滤器
export interface TableDataFilter {
  column: string
  operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in' | 'between' | 'null' | 'not_null'
  value: any
}

// 表数据排序
export interface TableDataSort {
  column: string
  direction: 'asc' | 'desc'
}

// 表数据查询参数
export interface TableDataQuery {
  page?: number
  pageSize?: number
  filters?: TableDataFilter[]
  sorts?: TableDataSort[]
  columns?: string[]
}

// 导出选项
export interface ExportOptions {
  format: 'sql' | 'csv' | 'json' | 'xlsx'
  includeStructure?: boolean
  includeData?: boolean
  includeIndexes?: boolean
  includeForeignKeys?: boolean
  includeComments?: boolean
  dataFilter?: TableDataFilter[]
  columns?: string[]
}

// 导入选项
export interface ImportOptions {
  format: 'sql' | 'csv' | 'json' | 'xlsx'
  tableName?: string
  createTable?: boolean
  truncateTable?: boolean
  skipErrors?: boolean
  batchSize?: number
  fieldMapping?: Record<string, string>
}

// 表结构定义（用于创建表）
export interface TableSchema {
  name: string
  schema?: string
  comment?: string
  engine?: string
  charset?: string
  collation?: string
  columns: ColumnSchema[]
  indexes?: IndexSchema[]
  foreignKeys?: ForeignKeySchema[]
  advancedOptions?: Record<string, any>
}

// 列结构定义
export interface ColumnSchema {
  name: string
  type: string
  length?: number
  precision?: number
  scale?: number
  notNull?: boolean
  primaryKey?: boolean
  autoIncrement?: boolean
  defaultValue?: string
  comment?: string
  charset?: string
  collation?: string
  values?: string[]
  extra?: string
}

// 索引结构定义
export interface IndexSchema {
  name: string
  type: string
  columns: string[]
  comment?: string
}

// 外键结构定义
export interface ForeignKeySchema {
  name: string
  columns: string[]
  referenceTable: string
  referenceColumns: string[]
  updateRule?: string
  deleteRule?: string
}

// 表修改结构定义
export interface TableAlterSchema {
  // 列操作
  addColumns?: ColumnSchema[]
  modifyColumns?: ColumnSchema[]
  dropColumns?: string[]
  renameColumns?: Record<string, string>
  
  // 索引操作
  addIndexes?: IndexSchema[]
  dropIndexes?: string[]
  
  // 外键操作
  addForeignKeys?: ForeignKeySchema[]
  dropForeignKeys?: string[]
  
  // 表级选项修改
  engine?: string
  charset?: string
  collation?: string
  comment?: string
} 